CREATE TABLE [dbo].[SystemEntity]
(
[SystemEntityKey] [uniqueidentifier] NOT NULL CONSTRAINT [DF_SystemEntity_SystemEntityKey] DEFAULT (newid()),
[SystemKeyword] [nvarchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SystemEntity_SystemKeyword] DEFAULT (''),
[IsActive] [bit] NOT NULL CONSTRAINT [DF_SystemEntity_IsActive] DEFAULT ((0)),
[IsDefault] [bit] NOT NULL CONSTRAINT [DF_SystemEntity_IsDefault] DEFAULT ((0)),
[Name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SystemEntity_Name] DEFAULT (''),
[Description] [nvarchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SystemEntity_Description] DEFAULT (''),
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[UpdatedOn] [datetime] NULL,
[ApplicationAccessKey] [uniqueidentifier] NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[AccessKey] [uniqueidentifier] NOT NULL,
[OrganizationKey] [uniqueidentifier] NOT NULL,
[MarkedForDeleteOn] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SystemEntity] ADD CONSTRAINT [PK_SystemEntity] PRIMARY KEY CLUSTERED ([SystemEntityKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SystemEntity_AccessKey] ON [dbo].[SystemEntity] ([AccessKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SystemEntity_ApplicationAccessKey] ON [dbo].[SystemEntity] ([ApplicationAccessKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SystemEntity_CreatedByUserKey] ON [dbo].[SystemEntity] ([CreatedByUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SystemEntity_OrganizationKey] ON [dbo].[SystemEntity] ([OrganizationKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SystemEntity_SystemKeyword] ON [dbo].[SystemEntity] ([SystemKeyword]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SystemEntity_UpdatedByUserKey] ON [dbo].[SystemEntity] ([UpdatedByUserKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SystemEntity] ADD CONSTRAINT [FK_SystemEntity_AccessMain] FOREIGN KEY ([AccessKey]) REFERENCES [dbo].[AccessMain] ([AccessKey])
GO
ALTER TABLE [dbo].[SystemEntity] ADD CONSTRAINT [FK_SystemEntity_AccessMain_ApplicationAccessKey] FOREIGN KEY ([ApplicationAccessKey]) REFERENCES [dbo].[AccessMain] ([AccessKey])
GO
ALTER TABLE [dbo].[SystemEntity] ADD CONSTRAINT [FK_SystemEntity_OrganizationMain] FOREIGN KEY ([OrganizationKey]) REFERENCES [dbo].[OrganizationMain] ([OrganizationKey])
GO
ALTER TABLE [dbo].[SystemEntity] ADD CONSTRAINT [FK_SystemEntity_SystemRef] FOREIGN KEY ([SystemKeyword]) REFERENCES [dbo].[SystemRef] ([SystemKeyword])
GO
ALTER TABLE [dbo].[SystemEntity] ADD CONSTRAINT [FK_SystemEntity_UniformRegistry] FOREIGN KEY ([SystemEntityKey]) REFERENCES [dbo].[UniformRegistry] ([UniformKey])
GO
ALTER TABLE [dbo].[SystemEntity] ADD CONSTRAINT [FK_SystemEntity_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[SystemEntity] ADD CONSTRAINT [FK_SystemEntity_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
GRANT SELECT ON [dbo].[SystemEntity] TO [IMIS]
GO